import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

/// 运行 flutter driver --target=test_driver/integrationApp.dart
void main() {
  group('Counter App', () {
    // 定义Finders
    final counterTextFinder = find.byValueKey('counter');
    // 获取按钮
    final buttonFinder = find.byValueKey('increment');

    FlutterDriver driver;
    // 连接
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    // 断开连接
    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    });

    test('start at 0', () async {
      expect(await driver.getText(counterTextFinder), '0');
    });

    test('increments the counter', () async {
      for (int i = 0; i < 10; i++) {
        await driver.tap(buttonFinder);
      }
      await driver.tap(buttonFinder);
      // 判断获取到的值是否一致
//      expect(await driver.getText(counterTextFinder), '1');
      print(await driver.getText(counterTextFinder));
    });
  });
}
